package org.thread.test05.syn.homework.demo03;

/**
 * 账户类
 * @author CSY
 * @date 2025 - 03 - 12
 */
public class Account {
    /**
     *
     * 余额
     */
    private double surplus;

    public Account() {
    }

    public Account(double surplus) {
        this.surplus = surplus;
    }

    /**
     * 取钱
     * @param user 取钱用户
     * @param money 取出金额
     */
    public synchronized void getMoney(String user,double money) {
        System.out.printf("%s取了%.1f元，",user,money);
        if(this.surplus >= money){
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            this.surplus -= money;
            System.out.printf("余额为：%.1f %n",this.surplus);
            return;
        }

        System.out.printf("取款失败，余额为：%.1f %n",this.surplus);


    }


    public double getSurplus() {
        return surplus;
    }

    public void setSurplus(double surplus) {
        this.surplus = surplus;
    }
}
